home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz)
- Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
- Subject: Re: C coding problem
- Date: 6 Apr 1996 08:41:56 -0600
- Organization: TU Wien
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4k5vrk$a2d@solutions.solon.com>
- References: <4j06na$808@solutions.solon.com> <4jttan$3gf@solutions.solon.com> <4jv6st$crf@solutions.solon.com> <4k1qh3$5hn@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4k1qh3$5hn@solutions.solon.com>, news@Thinkage.On.CA writes:
-
- |> However it is not always so that the machine does a distinct
- |> add or multiply in order to handle a[i]. The "*p++" idiom may look
- |> shot in the C code, and on a PDP-11 it usually resulted in nice
- |> short code. However, there is no guarentee that this is true of all
- |> hardware. It is not all that uncommon to have an architecture where
- |> adding 1 to an int is much cheaper than adding one to a pointer,
-
- Examples? The dominant trend in computer architecture seems to be the
- reduced instruction set with simple addressing modes; Mips and Alpha
- are two architectures that do not have an indexed addressing mode.
-
- |> In such and environment,
- |> *q++ = *p++;
- |> loses badly to
- |> q[i] = p[i], ++i;
- |> if the hardware indexing works in terms of the objects being
- |> referenced.
-
- Note that indexed addressing often works only for small
- powers of two, e.g., x86 family.
-
- |> Pointer notation can greatly reduce program
- |> clutter so you can see what is happening.
-
- Agreed. :)
-
- Konrad Schwarz
-